package com.sdgs.paas.sdk.core.log;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.spi.ExtendedLogger;
import org.apache.logging.slf4j.Log4jLogger;
import org.apache.logging.slf4j.Log4jMarker;
import org.apache.logging.slf4j.Log4jMarkerFactory;
import org.slf4j.Marker;
import org.slf4j.impl.StaticMarkerBinder;
/**
 * 自定义Logger,解决异步日志输出代码位置不准确的问题
 * 
 * @author wjj
 *
 */
public class PaasLog4jLogger extends Log4jLogger {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3004636318590710795L;
	private final String FQCN = PaasLogger.class.getName();
	private transient ExtendedLogger logger;


	public PaasLog4jLogger(ExtendedLogger logger, String name) {
		super(logger, name);
		this.logger = logger;

	}

	private static org.apache.logging.log4j.Marker getMarker(final Marker marker) {
		if (marker == null) {
			return null;
		} else if (marker instanceof Log4jMarker) {
			return ((Log4jMarker) marker).getLog4jMarker();
		} else {
			final Log4jMarkerFactory factory = (Log4jMarkerFactory) StaticMarkerBinder.SINGLETON.getMarkerFactory();
			return ((Log4jMarker) factory.getMarker(marker)).getLog4jMarker();
		}
	}

	@Override
	public void trace(final String format) {
		logger.logIfEnabled(FQCN, Level.TRACE, null, format);
	}

	@Override
	public void trace(final String format, final Object o) {
		logger.logIfEnabled(FQCN, Level.TRACE, null, format, o);
	}

	@Override
	public void trace(final String format, final Object arg1, final Object arg2) {
		logger.logIfEnabled(FQCN, Level.TRACE, null, format, arg1, arg2);
	}

	@Override
	public void trace(final String format, final Object... args) {
		logger.logIfEnabled(FQCN, Level.TRACE, null, format, args);
	}

	@Override
	public void trace(final String format, final Throwable t) {
		logger.logIfEnabled(FQCN, Level.TRACE, null, format, t);
	}

	@Override
	public boolean isTraceEnabled() {
		return logger.isEnabled(Level.TRACE, null, null);
	}

	@Override
	public boolean isTraceEnabled(final Marker marker) {
		return logger.isEnabled(Level.TRACE, getMarker(marker), null);
	}

	@Override
	public void trace(final Marker marker, final String s) {
		logger.logIfEnabled(FQCN, Level.TRACE, getMarker(marker), s);
	}

	@Override
	public void trace(final Marker marker, final String s, final Object o) {
		logger.logIfEnabled(FQCN, Level.TRACE, getMarker(marker), s, o);
	}

	@Override
	public void trace(final Marker marker, final String s, final Object o, final Object o1) {
		logger.logIfEnabled(FQCN, Level.TRACE, getMarker(marker), s, o, o1);
	}

	@Override
	public void trace(final Marker marker, final String s, final Object... objects) {
		logger.logIfEnabled(FQCN, Level.TRACE, getMarker(marker), s, objects);
	}

	@Override
	public void trace(final Marker marker, final String s, final Throwable throwable) {
		logger.logIfEnabled(FQCN, Level.TRACE, getMarker(marker), s, throwable);
	}

	@Override
	public void debug(final String format) {
		logger.logIfEnabled(FQCN, Level.DEBUG, null, format);
	}

	@Override
	public void debug(final String format, final Object o) {
		logger.logIfEnabled(FQCN, Level.DEBUG, null, format, o);
	}

	@Override
	public void debug(final String format, final Object arg1, final Object arg2) {
		logger.logIfEnabled(FQCN, Level.DEBUG, null, format, arg1, arg2);
	}

	@Override
	public void debug(final String format, final Object... args) {
		logger.logIfEnabled(FQCN, Level.DEBUG, null, format, args);
	}

	@Override
	public void debug(final String format, final Throwable t) {
		logger.logIfEnabled(FQCN, Level.DEBUG, null, format, t);
	}

	@Override
	public boolean isDebugEnabled() {
		return logger.isEnabled(Level.DEBUG, null, null);
	}

	@Override
	public boolean isDebugEnabled(final Marker marker) {
		return logger.isEnabled(Level.DEBUG, getMarker(marker), null);
	}

	@Override
	public void debug(final Marker marker, final String s) {
		logger.logIfEnabled(FQCN, Level.DEBUG, getMarker(marker), s);
	}

	@Override
	public void debug(final Marker marker, final String s, final Object o) {
		logger.logIfEnabled(FQCN, Level.DEBUG, getMarker(marker), s, o);
	}

	@Override
	public void debug(final Marker marker, final String s, final Object o, final Object o1) {
		logger.logIfEnabled(FQCN, Level.DEBUG, getMarker(marker), s, o, o1);
	}

	@Override
	public void debug(final Marker marker, final String s, final Object... objects) {
		logger.logIfEnabled(FQCN, Level.DEBUG, getMarker(marker), s, objects);
	}

	@Override
	public void debug(final Marker marker, final String s, final Throwable throwable) {
		logger.logIfEnabled(FQCN, Level.DEBUG, getMarker(marker), s, throwable);
	}

	@Override
	public void info(final String format) {
		logger.logIfEnabled(FQCN, Level.INFO, null, format);
	}

	@Override
	public void info(final String format, final Object o) {
		logger.logIfEnabled(FQCN, Level.INFO, null, format, o);
	}

	@Override
	public void info(final String format, final Object arg1, final Object arg2) {
		logger.logIfEnabled(FQCN, Level.INFO, null, format, arg1, arg2);
	}

	@Override
	public void info(final String format, final Object... args) {
		logger.logIfEnabled(FQCN, Level.INFO, null, format, args);
	}

	@Override
	public void info(final String format, final Throwable t) {
		logger.logIfEnabled(FQCN, Level.INFO, null, format, t);
	}

	@Override
	public boolean isInfoEnabled() {
		return logger.isEnabled(Level.INFO, null, null);
	}

	@Override
	public boolean isInfoEnabled(final Marker marker) {
		return logger.isEnabled(Level.INFO, getMarker(marker), null);
	}

	@Override
	public void info(final Marker marker, final String s) {
		logger.logIfEnabled(FQCN, Level.INFO, getMarker(marker), s);
	}

	@Override
	public void info(final Marker marker, final String s, final Object o) {
		logger.logIfEnabled(FQCN, Level.INFO, getMarker(marker), s, o);
	}

	@Override
	public void info(final Marker marker, final String s, final Object o, final Object o1) {
		logger.logIfEnabled(FQCN, Level.INFO, getMarker(marker), s, o, o1);
	}

	@Override
	public void info(final Marker marker, final String s, final Object... objects) {
		logger.logIfEnabled(FQCN, Level.INFO, getMarker(marker), s, objects);
	}

	@Override
	public void info(final Marker marker, final String s, final Throwable throwable) {
		logger.logIfEnabled(FQCN, Level.INFO, getMarker(marker), s, throwable);
	}

	@Override
	public void warn(final String format) {
		logger.logIfEnabled(FQCN, Level.WARN, null, format);
	}

	@Override
	public void warn(final String format, final Object o) {
		logger.logIfEnabled(FQCN, Level.WARN, null, format, o);
	}

	@Override
	public void warn(final String format, final Object arg1, final Object arg2) {
		logger.logIfEnabled(FQCN, Level.WARN, null, format, arg1, arg2);
	}

	@Override
	public void warn(final String format, final Object... args) {
		logger.logIfEnabled(FQCN, Level.WARN, null, format, args);
	}

	@Override
	public void warn(final String format, final Throwable t) {
		logger.logIfEnabled(FQCN, Level.WARN, null, format, t);
	}

	@Override
	public boolean isWarnEnabled() {
		return logger.isEnabled(Level.WARN, null, null);
	}

	@Override
	public boolean isWarnEnabled(final Marker marker) {
		return logger.isEnabled(Level.WARN, getMarker(marker), null);
	}

	@Override
	public void warn(final Marker marker, final String s) {
		logger.logIfEnabled(FQCN, Level.WARN, getMarker(marker), s);
	}

	@Override
	public void warn(final Marker marker, final String s, final Object o) {
		logger.logIfEnabled(FQCN, Level.WARN, getMarker(marker), s, o);
	}

	@Override
	public void warn(final Marker marker, final String s, final Object o, final Object o1) {
		logger.logIfEnabled(FQCN, Level.WARN, getMarker(marker), s, o, o1);
	}

	@Override
	public void warn(final Marker marker, final String s, final Object... objects) {
		logger.logIfEnabled(FQCN, Level.WARN, getMarker(marker), s, objects);
	}

	@Override
	public void warn(final Marker marker, final String s, final Throwable throwable) {
		logger.logIfEnabled(FQCN, Level.WARN, getMarker(marker), s, throwable);
	}

	@Override
	public void error(final String format) {
		logger.logIfEnabled(FQCN, Level.ERROR, null, format);
	}

	@Override
	public void error(final String format, final Object o) {
		logger.logIfEnabled(FQCN, Level.ERROR, null, format, o);
	}

	@Override
	public void error(final String format, final Object arg1, final Object arg2) {
		logger.logIfEnabled(FQCN, Level.ERROR, null, format, arg1, arg2);
	}

	@Override
	public void error(final String format, final Object... args) {
		logger.logIfEnabled(FQCN, Level.ERROR, null, format, args);
	}

	@Override
	public void error(final String format, final Throwable t) {
		logger.logIfEnabled(FQCN, Level.ERROR, null, format, t);
	}

	@Override
	public boolean isErrorEnabled() {
		return logger.isEnabled(Level.ERROR, null, null);
	}

	@Override
	public boolean isErrorEnabled(final Marker marker) {
		return logger.isEnabled(Level.ERROR, getMarker(marker), null);
	}

	@Override
	public void error(final Marker marker, final String s) {
		logger.logIfEnabled(FQCN, Level.ERROR, getMarker(marker), s);
	}

	@Override
	public void error(final Marker marker, final String s, final Object o) {
		logger.logIfEnabled(FQCN, Level.ERROR, getMarker(marker), s, o);
	}

	@Override
	public void error(final Marker marker, final String s, final Object o, final Object o1) {
		logger.logIfEnabled(FQCN, Level.ERROR, getMarker(marker), s, o, o1);
	}

	@Override
	public void error(final Marker marker, final String s, final Object... objects) {
		logger.logIfEnabled(FQCN, Level.ERROR, getMarker(marker), s, objects);
	}

	@Override
	public void error(final Marker marker, final String s, final Throwable throwable) {
		logger.logIfEnabled(FQCN, Level.ERROR, getMarker(marker), s, throwable);
	}

}
